//package com.efounder.view.imageaffixview;
//
//import android.content.Context;
//import android.content.DialogInterface;
//import android.support.annotation.Nullable;
//import android.support.v7.app.AlertDialog;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.util.AttributeSet;
//import android.view.View;
//
//import com.efounder.mobilemanager.R;
//import com.readystatesoftware.viewbadger.BadgeView;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//
///**
// * 影像附件组件
// */
//
//@Deprecated
//public class ImgAffixReimburseComps extends RecyclerView {
//    private static final String TAG = "ImgAffixComps";
//
//    LinearLayoutManager linearLayoutManager;
//    Context mContext;
//    public ViewAdapter mAdapter;
//    public ArrayList<ImageModel> imageModelList = new ArrayList<ImageModel>();
//    /**image 是否上传完毕标示 */
//    private ArrayList<ImageModel> imageModelListForUpLoadFlag = new ArrayList<ImageModel>();
//
//    BadgeView badgeView;//图片数量角标
//
//    /**是否来自单据预览*/
//    boolean isFromChatUI;
//    /**是否可编辑*/
//    boolean isEditable;
//
//
//
//    public ImgAffixReimburseComps(Context context) {
//        super(context);
//        intBase(context);
//    }
//
//    public ImgAffixReimburseComps(Context context, @Nullable AttributeSet attrs) {
//        super(context, attrs);
//        intBase(context);
//    }
//
//    public ImgAffixReimburseComps(Context context, @Nullable AttributeSet attrs, int defStyle) {
//        super(context, attrs, defStyle);
//        intBase(context);
//    }
//
//    private void intBase(Context context){
//        //初始化样式
//        linearLayoutManager = new LinearLayoutManager(context);
//        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//        this.setLayoutManager(linearLayoutManager);
//        this.setPadding(0, 0, 0, 0);
//
//        this.mContext = context;
//
//        mAdapter = new ViewAdapter(context, imageModelList);
//        mAdapter.setShowAddButton(false);
//////        mAdapter.setImageWidth(60);
////        mAdapter.setImageHeight(115);
//
//        this.setAdapter(mAdapter);
//
////        initBadgeView();
//    }
//
//    /**
//     * 初始化BadgeView
//     */
//    public void initBadgeView(View view){
//        //图片数量角标
//        badgeView = new BadgeView(mContext, view);
//        badgeView.setBadgeMargin(0, 0);
//        badgeView.setTextSize(13);
//        badgeView.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
//        if (imageModelList.size() <= 0) {
//            badgeView.setVisibility(View.INVISIBLE);
//        } else {
//            badgeView.setText(imageModelList.size()+"");
//            badgeView.show();
//        }
//    }
//
//
//    /**是否来自展示界面*/
//    public void setFromChatUI(boolean fromChatUI) {
//        isFromChatUI = fromChatUI;
//    }
//
//    /**是否可编辑*/
//    public void setEditable(boolean editable) {
//        isEditable = editable;
//    }
//
//    public boolean isFromChatUI() {
//        return isFromChatUI;
//    }
//
//    public boolean isEditable() {
//        return isEditable;
//    }
//
//    /**手动设置点击监听*/
//    public void initListener(){
//        mAdapter.setOnItemClickListener(new ViewAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position) {
//                //点击最后的加号，如果是创建则进入拍照活动，否则不处理
//                if (position == imageModelList.size()) {
//                    if(!isFromChatUI||isEditable){
////                        Intent intent = new Intent(mContext,EFAppAccountDJZCameraActivityNN.class);
////                        mContext.startActivity(intent);
//                    }
//                }else{//查看图片
//                    if (onAffixItemClickListener != null){
//                        onAffixItemClickListener.onAffixItemClick(view,position);
//                    }
//                }
//            }
//
//            @Override
//            public void onIconDeleteClick(View view, int position) {
//                removeImageModel(position);
//                if (onItemRemoveListener != null) {
//                    onItemRemoveListener.onItemRemove(position);
//                }
//            }
//
//            @Override
//            public void onItemLongClick(View view, final int position) {
//                final ImageModel imageModel = imageModelList.get(position);
//                if(!imageModel.isUploadSuccess()){
//                    AlertDialog alertDialog = new AlertDialog.Builder(mContext).setTitle(R.string.common_text_hint).setMessage("重新上传").setPositiveButton(R.string.common_text_confirm, new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            try {
//                                imageModel.setUploadSuccess(true);
//                                mAdapter.notifyDataSetChanged();
//                                upLoadFileN(imageModel);
////                                doUpLoadImage(imageModel);
//                                dialog.dismiss();
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    }).create();
//                    alertDialog.show();
//                }
//            }
//        });
//
//    }
//    /**
//     * 增加影像
//     * @param imageModel
//     */
//    public void addImageModel(ImageModel imageModel){
//        imageModelList.add(imageModel);
//        mAdapter.notifyDataSetChanged();
////        changeBadgeViewNum();
//    }
//
//    /**
//     * 增加影像
//     * @param
//     */
//    public void addListImageModel(List<ImageModel> imageModels, boolean notify){
//        this.imageModelList.clear();
//        this.imageModelList.addAll(imageModels);
//        if (notify) {
//            mAdapter.notifyDataSetChanged();
//        }
////        changeBadgeViewNum();
//    }
//
//    /**
//     * 删除影像
//     * @param pos
//     */
//    public void removeImageModel(int pos){
//        if(imageModelList.size()>pos){
//            imageModelList.remove(pos);
//            mAdapter.notifyDataSetChanged();
////            changeBadgeViewNum();
//        }
//    }
//
//    /**
//     * 影像是否上传完毕 上传完毕 单据允许提交 未上传完毕不可提交
//     * @return
//     */
//    public boolean isDJCommitable(){
//        boolean hasUploadErrorImage = false;
//        if(imageModelList.size()>0){//判断是否含有上传失败的影像
//            for(ImageModel imageModel : imageModelList){
//                if(!imageModel.isUploadSuccess()){
//                    hasUploadErrorImage = true;
//                    break;
//                }
//            }
//        }
//        return imageModelListForUpLoadFlag.size()==0&&!hasUploadErrorImage ?true:false;
//    }
//
//
//    /**
//     * 操作附件后 更改附件张数提示
//     */
//    private void changeBadgeViewNum(){
//        if (imageModelList.size() <= 0) {
//            badgeView.setVisibility(View.INVISIBLE);
//        } else {
//            badgeView.setText(imageModelList.size()+"");
//            badgeView.show();
//        }
//    }
//
//
//
//    public void doUpLoadResult(ImageModel imageModel){
//        imageModelList.add(imageModel);
//        mAdapter.notifyDataSetChanged();
//        //TODO 七牛上传
////        doUpLoadImage(imageModel);
//        imageModelListForUpLoadFlag.add(imageModel);
//        try {
//            upLoadFileN(imageModel);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
////        changeBadgeViewNum();
//    }
//
//    /**
//     * 七牛上传图片
//     * @param imageModel
//     */
//    private void doUpLoadImage(final ImageModel imageModel){
////        QiNiuUtil.getQiNiuResWithProgress(imageModel.getOrgUrl(), new QiNiuUtil.UpLoadListenerWithProgress() {
////            @Override
////            public void getHttpUrl(Boolean isSuccess, String url) {
////                if(isSuccess){
////                    Log.i(TAG,"---url:"+url);
////                    imageModelListForUpLoadFlag.remove(imageModel);
////                    imageModel.setRemoteUrl(url);
////                    imageModel.setProgress(100);
////                    imageModel.setUploadSuccess(true);
////                    mAdapter.notifyDataSetChanged();
////                }else{//TODO 上传失败
////                    Log.i(TAG,"---上传失败---");
////                    imageModelListForUpLoadFlag.remove(imageModel);
////                    ToastUtil.showToast(mContext,"上传失败，请长按重新上传");
////                    imageModel.setUploadSuccess(false);
////                    mAdapter.notifyDataSetChanged();
////                }
////            }
////            @Override
////            public void getHttpProgress(int progress) {
////                Log.i("上传进度:",String.valueOf(progress));
//////                imageModel.setProgress(progress / 10);
//////                mAdapter.notifyDataSetChanged();
////            }
////        });
////        this.scrollToPosition(imageModelList.size());
////        if(mAdapter!=null)
////            mAdapter.notifyDataSetChanged();
//    }
//
//
//
//    private HashMap<String,String> djMapParams;//要发送的表单数据
//
//    /**
//     * 传递单据GUID
//     * @param djMapParams
//     */
//    public void setDjMapParams(HashMap<String, String> djMapParams) {
//        this.djMapParams = djMapParams;
//    }
//
//    //TODO 上传 油田
//    private void upLoadFileN(final ImageModel imgeModel) throws Exception{
////        File file = new File(imgeModel.getOrgUrl());
////        byte[] data = FileUtils.FileToByte(imgeModel.getOrgUrl());
////        String fileName = imgeModel.getOrgUrl().substring(imgeModel.getOrgUrl().lastIndexOf("/")+1);
////        Base64Encoder encoder = new Base64Encoder();
////        String dataStr = encoder.encode(data);
////        String imgId;
////        if (imgeModel.getImgId()==null||imgeModel.getImgId().equals("")) {
////            imgId = UUID.randomUUID().toString();
////            imgeModel.setImgId(imgId);
////        }
////        HashMap<String,String> params = new HashMap<>();
////        params.put("fileName",fileName);
////        params.put("guid",djMapParams.get("guid"));
////        params.put("imgid",imgeModel.getImgId());
////
////        params.put("byt",dataStr);
////        params.put("file",imgeModel.getOrgUrl());
////
////        RequestManager.getInstance(mContext).upLoadFileNT("CtrlService?action=ImgUploadService", params, new RequestManager.ReqCallBack<String>() {
////            /**
////             * 响应成功
////             */
////            @Override
////            public void onReqSuccess(String result) {
////                Log.i(TAG, "--------result:" + result);
////                imageModelListForUpLoadFlag.remove(imgeModel);
////                JSONObject obj = null;
////                try {
////                    obj = new JSONObject(result);
////                    String basePath = obj.getString("basePath");
////                    imgeModel.setRemoteUrl(basePath);
////                    imgeModel.setProgress(100);
////                    imgeModel.setUploadSuccess(true);
////                    mAdapter.notifyDataSetChanged();
////                    if(onUploadAffixFinishCallBack!=null){
////                        onUploadAffixFinishCallBack.onUploadFinishCallBack(imgeModel);
////                    }
//////                    getImgUrl(imgeModel,basePath);
////                } catch (JSONException e) {
////                    e.printStackTrace();
////                }
////            }
////
////            /**
////             * 响应失败
////             */
////            @Override
////            public void onReqFailed(String errorMsg) {
////                Log.i(TAG, "---------errorMsg:" + errorMsg);//防止图片上传失败情况下不可提交情况
////                imageModelListForUpLoadFlag.remove(imgeModel);
////                ToastUtil.showToast(mContext,"上传失败，请长按重新上传");
////                imgeModel.setUploadSuccess(false);
////                mAdapter.notifyDataSetChanged();
////            }
////        });
////
////        this.scrollToPosition(imageModelList.size());
////        if(mAdapter!=null)
////            mAdapter.notifyDataSetChanged();
////        Log.i(TAG,"--------over-------");
//    }
//
//    /**
//     * 派发 上传成功后的IMAGEMODEL
//     */
//    public interface OnUploadAffixFinishCallBack{
//        public void onUploadFinishCallBack(ImageModel imageModel);
//    }
//
//    private OnUploadAffixFinishCallBack onUploadAffixFinishCallBack;
//
//    public void setOnUploadAffixFinishCallBack(OnUploadAffixFinishCallBack onUploadAffixFinishCallBack) {
//        this.onUploadAffixFinishCallBack = onUploadAffixFinishCallBack;
//    }
//
//    public interface OnAffixItemClickListener{
//        public void onAffixItemClick(View view, int position);
//    }
//
//    private OnAffixItemClickListener onAffixItemClickListener;
//
//    public OnAffixItemClickListener getOnAffixItemClickListener() {
//        return onAffixItemClickListener;
//    }
//
//    public void setOnAffixItemClickListener(OnAffixItemClickListener onAffixItemClickListener) {
//        this.onAffixItemClickListener = onAffixItemClickListener;
//    }
//
//    public interface OnItemRemoveListener {
//        void onItemRemove(int position);
//    }
//
//    private OnItemRemoveListener onItemRemoveListener;
//
//    public OnItemRemoveListener getOnItemRemoveListener() {
//        return onItemRemoveListener;
//    }
//
//    public void setOnItemRemoveListener(OnItemRemoveListener onItemRemoveListener) {
//        this.onItemRemoveListener = onItemRemoveListener;
//    }
//
//}
